package com.zhuiwei.initialization;
import static net.mindview.util.Print.print;

/**
 * 非静态实例初始化
 * @author zhuiwei
 * @see 《java编程思想 第四版》5.7.4
 */

class Mug {
  Mug(int marker) {
    print("Mug(" + marker + ")");
  }
  void f(int marker) {
    print("f(" + marker + ")");
  }
}


public class Mugs {
  Mug mug1;
  Mug mug2;
  {
    mug1 = new Mug(1);
    mug2 = new Mug(2);
    print("mug1 & mug2 initialized");
  }

  Mugs() {
    print("Mugs()");
  }

  Mugs(int i) {
    print("Mugs(int)");
  }

  //练习编码
  static String str;
  static {
    str="这是练习题";
  }
  Mugs(Boolean isLianXi) {
    print(str);
  }

  public static void main(String[] args) {
    print("Inside main()");
    new Mugs();
    print("new Mugs() completed");
    new Mugs(1);
    print("new Mugs(1) completed");
    /**
     * 练习编写一个含有字符串域的类，并采用实例初始化方式进行初始化。
     * 以下是练习答案
     * */
    print("练习题输出结果：");
    new Mugs(true);

  }
}


/*
输出结果:
Inside main()
Mug(1)
Mug(2)
mug1 & mug2 initialized
Mugs()
new Mugs() completed
Mug(1)
Mug(2)
mug1 & mug2 initialized
Mugs(int)
new Mugs(1) completed
*/

/**
 * 说明：
 * 调用构造器，都会发生非静态实例初始化
 */
